/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import jWASA.PHR;
import NetCommunicator.NetCommunicator;
import NetCommunicator.ServerDownException;
import jWASA.User;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.sql.Date;
import java.sql.Time;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gianmariospacagna
 */
public class Controller {

    NetCommunicator communicator;

    public Controller() {
        serverOnLine = false;
    }
    Boolean serverOnLine;

    public void connectServer(String host, String port) throws ServerDownException {
        try {
            communicator = new NetCommunicator(Inet4Address.getByName(host), Integer.parseInt(port));
            serverOnLine = true;
        } catch (UnknownHostException ex) {
            Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
            serverOnLine = false;
            throw new ServerDownException();
        }
    }

    public void sendPHR(String user, String date, String time, String place, String syntompsDescription, String routineDescription, HashSet<String> tags) throws ServerDownException {
        if (!serverOnLine) {
            throw new ServerDownException();
        }
        PHR phr = new PHR(user, Date.valueOf(date), Time.valueOf(time), place, syntompsDescription, routineDescription, tags);
        communicator.sendData(phr);

    }
}
